<style type="text/css">
.sizetable th,.sizetable td{padding:3px 5px !important;text-align:center;}
.layui-table td, .layui-table th {padding:6px 9px;}
</style>
    <div>
        <form  class="layui-form layui-form-pane fixed-bar-form" action="{:url('')}" method="post" id="hisi-table-search">
       <div>
        	<table class="layui-table" style="width:100%" id="demo1" lay-filter="demo1">
                <thead>
                    <tr>
                      <th>process_id</th>
                        <th>工序名称选择</th>
                        <th>工价 <span style="color:#CCCCCC;font-size:12px;margin-bottom:2px;">按【Tab】键可切换到下一行</span></th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody class="edit_process_body">
                    {foreach $datalist as $k => $v}
                    <tr>
                      <td style="padding:3px 10px;">{$v['id']}<input type="hidden" name="data_id[]" value="{$v['id']}"></td>
                          <td><input type="hidden" name="process_name[]" value="{$v['process_name']}" class="process_name_input" autocomplete="off">
                          	{:Form::select('process_name_id[]', $v["process_name_id"], ['' => '--请选择--']+$processNameList, '', '','lay-verify="required" onchange="setProcessName(this)" lay-ignore')}
                          </td>
                          <td><input type="text" name="process_price[]" value="{$v['process_price']}" class="process_price_input" lay-verify="required|number" tabindex="100" autocomplete="off" style="width:100px;"></td>
                      <td><a class="layui-btn layui-btn-xs layui-btn-danger" style="margin-left:5px;" lay-event="delete" onclick="removePrice(this)">删除</a></td>
                    </tr>
                    {/foreach}
                </tbody>
            </table>
         <input type="hidden" name="stage" value="{$stage}">
         <input type="hidden" name="sku" value="{$sku}">
         <input type="hidden" name="delete_ids" value="">
         <div style="text-align:center;"><a class="layui-btn layui-btn-xs layui-btn-danger processAdd" lay-event="processAdd">新增{$stagelist[$stage]}工序</a></div>
        <div class="pop-bottom-bar">
            	<button type="submit" class="layui-btn"  btn_name="edit_one" lay-submit="" uploadToJinP='0' lay-filter="demo1">提交保存</button>
                &nbsp;<button type="submit" class="layui-btn"  btn_name="edit_one" lay-submit="" uploadToJinP='1' lay-filter="demo1">保存并同步金鹏</button>&nbsp;
            
            <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
        </div>
       </div>

        </form>
    </div>
<div style="display:none">
<table id="dataTable"></table>
</div>
<div id="temp" style="display:none">
    <table id="temptable"><tr>
        <td style="padding:3px 10px;"><input type="hidden" name="data_id[]" value=""></td>
        <td><input type="hidden" name="process_name[]" value="" class="process_name_input" autocomplete="off">
        {:Form::select('process_name_id[]', '', ['' => '--请选择--']+$processNameList, '', '','lay-verify="required" onchange="setProcessName(this)" lay-ignore')}</td>
        <td><input type="text" name="process_price[]" value="" tabindex="100" autocomplete="off" lay-verify="required|number" style="width:100px;"></td>
        <td><a class="layui-btn layui-btn-xs layui-btn-danger" style="margin-left:5px;" lay-event="delete" onclick="removePrice(this)">删除</a></td>
    </tr>
    </table>
</div>
{include file="system@block/layui" /}
<script>
	layui.use(['tool','laydate','table','form'], function() {
		var element = layui.element;
		var layer = layui.layer;
		var $ = layui.jquery;
		var form = layui.form;
		var table = layui.table;
		table.render({
            elem: '#dataTable'
            ,url: "{:url('')}" //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: false
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
                 {field: 'create_time', title: '操作时间',templet: '#createTimeTpl', width:160}
                ,{field: 'stall_cost_type', title: '费用单类型'}
                ,{field: 'stall_cost_money', title: '费用单金额'}
                ,{field: 'pic', title: '图片',templet:'#picTpl'}
                ,{field: 'remark', title: '备注'}
                
            ]]
			,done:function(res) {
				$(".process_price_input").eq(0).select();
			}
        });
		function doSaveStock(data){
			var uploadtoJinp=data['uploadToJinP'];
			$.ajax({
			   type: "POST",
			   url: "{:url('mp/ProcessPrice/editProcessPrice?action=dosave')}",
			   data: data,
			   dataType:"json",
			   success: function(res){
					var data=res.data;
					if(res.code==1){
						successMsg='修改保存成功'
						if(uploadtoJinp==1){
							successMsg+='，'+data['msg'];
						}
						setTimeout(function(){
							parent.layui.layer.closeAll();
							parent.reloadTable();
						},1200);
						layer.msg(successMsg, {icon: 1,anim: 6});
						return;

					}else{
                        layer.msg(res.msg, {icon: 2,anim: 6});
						$("#action_result").html(res.msg);
					}

			   }
			});
		}
        form.on('submit(demo1)', function (data) {
            //表单数据formData
            var uploadtoJinp=$(this).attr("uploadToJinP");
			var formData;
            formData = data.field;
			formData['uploadToJinP'] = uploadtoJinp;
            doSaveStock(formData)
        })
		//新增时选择加工工序
    	window.setProcessName=function(d){
			$(d).parent().find(".process_name_input").val($(d).find("option:selected").text());
    	};
        $(document).on('click', '.processAdd', function(){
            var addhtml=$("#temptable").find("tr").eq(0).clone();
            $(".edit_process_body").append(addhtml);
        });
		
		// 监听物料切换，显示mes幅宽
		window.removePrice = function(e) {
			var tr=$(e).parent().parent();
			$(e).parent().parent().remove();

			//$(".edit_process_body").remove()
		}
	});
</script>